import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:sale/home_page.dart';
import 'package:sale/hotel_page.dart';
import 'package:sale/family_page.dart';
import 'package:sale/meeting_page.dart';
import 'package:sale/work_page.dart';
import 'package:sale/login_page.dart';
import 'package:sale/constants/app_constants.dart';
import 'package:sale/utils/auth_state.dart';
import 'package:sale/widgets/auth_wrapper.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  SystemChrome.setPreferredOrientations([
    DeviceOrientation.landscapeLeft,
    DeviceOrientation.landscapeRight,
  ]);
  runApp(
    ChangeNotifierProvider(
      create: (_) => AuthState(),
      child: const MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(
      const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarIconBrightness: Brightness.dark,
      ),
    );
    SystemChrome.setEnabledSystemUIMode(
      SystemUiMode.immersiveSticky,
      overlays: [],
    );
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: _buildAppTheme(),
      initialRoute: '/login',
      routes: {
        '/login': (context) => const LoginPage(),
        '/': (context) => const AuthWrapper(child: HomePage()),
        '/hotel': (context) => const AuthWrapper(child: HotelPage()),
        '/family': (context) => const AuthWrapper(child: FamilyPage()),
        '/meeting': (context) => const AuthWrapper(child: MeetingPage()),
        '/work': (context) => const AuthWrapper(child: WorkPage()),
      },
    );
  }

  ThemeData _buildAppTheme() {
    return ThemeData.light().copyWith(
      scaffoldBackgroundColor: Colors.transparent,
      colorScheme: ColorScheme.fromSwatch().copyWith(
        secondary: AppConstants.secondaryColor,
        primary: AppConstants.primaryColor,
      ),
      cardTheme: CardTheme(
        elevation: AppConstants.cardElevation,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(AppConstants.defaultBorderRadius),
        ),
      ),
      textTheme: TextTheme(
        headlineMedium: AppConstants.headingStyle.copyWith(
          color: AppConstants.primaryColor,
        ),
        titleMedium: AppConstants.subheadingStyle,
      ),
    );
  }
}
